package com.jzo2o.customer.controller.agency;

import cn.hutool.core.bean.BeanUtil;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import com.jzo2o.mvc.utils.UserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: wen
 * @Time: 2024-04-26 10:52
 * @Version: 1.0
 */

@RestController("agencyBankAccountController")
@RequestMapping("/agency/bank-account")
@Api(tags = "机构端 - 银行账户信息相关接口")
public class BankAccountController {

    @Resource
    private IBankAccountService bankAccountService;

    /**
     * 新增或更新银行账号信息
     *
     * @param dto
     */
    @PostMapping
    @ApiOperation("新增或更新银行账号信息")
    public void queryByServeProviderId(@RequestBody BankAccountUpsertReqDTO dto) {
        bankAccountService.upsert(dto);
    }


    /**
     * 获取当前用户银行账号
     *
     * @return
     */
    @GetMapping("/currentUserBankAccount")
    @ApiOperation("获取当前用户银行账号")
    public BankAccountResDTO queryCurrentUserBankAccount() {
        // 获取当前用户id
        BankAccount bankAccount = bankAccountService.getById(UserContext.currentUserId());
        return BeanUtil.toBean(bankAccount, BankAccountResDTO.class);
    }

}
